// index.js
Component({
	properties: {
		tpurl: {
			type: String,
			value: ''
		},
		spurl: {
			type: String,
			value: ''
		},
		scaleo:{
			type: Number,
			value: 0
		},
		scalet:{
			type: Number,
			value: 0
		},
		scalett:{
			type: Number,
			value: 0
		},
		rotationo:{
			type: Number,
			value: 0
		},
		rotationt:{
			type: Number,
			value: 0
		},
		rotationtt:{
			type: Number,
			value: 0
		},
		
		flag: {
			type: Boolean,
			value: ''
		}
	},
	data: {
			intervalId: null,
		},
	show() {

	},
	methods: {
		handleReady({
			detail
		}) {
			const xrScene = this.scene = detail.value;

			console.log('xr-scene----', xrScene);
			let that = this;
			this.data.intervalId = setInterval(function() {
				if (that.properties.flag) {
					
					that.handleShare();
				} else {
					clearTimeout(that.data.intervalId);
				}

			}, 700);
		},
		handleAssetsProgress: function({
			detail
		}) {
			console.log('assets progress', detail.value);
		},

		handleAssetsLoaded: function({
			detail
		}) {
			console.log('assets loaded', detail.value);
			this.setData({
				loaded: true
			});
		},
		handleARReady: function({
			detail
		}) {
			console.log('arReady');
			this.setData({
				arReady: true
			});
		},
		handleTick: function() {
			const xrSystem = wx.getXrFrameSystem();
			const trackerEl = this.scene.getElementById('tracker');
			if (!trackerEl) {
				return;
			}

			const tracker = trackerEl.getComponent(xrSystem.ARTracker);
			if (!tracker.arActive) {
				return
			}

			const position = tracker.getPosition(98, new xrSystem.Vector3(), false);

		},
		async handleShare() {
			let that = this;
			const options = {
				type: 'jpg',
				quality: 0.7
			};

			const base64 = await this.scene.share.captureToDataURLAsync(options);

			that.triggerEvent("startBase64", base64)
		},
		//保存图片

		async imageSave() {
			const options = {
				type: 'jpg',
				quality: 0.7
			};
			await this.scene.share.captureToFriends(options);
		},

		//录制视频
		async recordVideo(status) {
			const options = {
				fps: 25,
				width: this.scene.width,
				height: this.scene.height,
				videoBitsPerSecond: 1000
			};

			switch (status) {
				case 1:
					// 启动录制
					await this.scene.share.recordStart(options);
					break;
				case 2:
					// 停止录制，直接保存到相册
					await this.scene.share.recordFinishToAlbum(options);
					break;
			}

		}



	}
})